package cn.tedu.onlinestore.product.service.serviceimpl;

import cn.tedu.onlinestore.product.mapper.ProductMapper;
import cn.tedu.onlinestore.product.pojo.dto.ProductParam;
import cn.tedu.onlinestore.product.pojo.entity.Product;
import cn.tedu.onlinestore.product.pojo.vo.ProductVO;
import cn.tedu.onlinestore.product.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    ProductMapper productMapper;

    @Override
    public void addProduct(ProductParam productParam) {
        log.debug("新增商品业务:{}",productParam);
        Product product = new Product();
        BeanUtils.copyProperties(productParam,product);
        product.setCreateTime(new Date());
        productMapper.addProduct(product);
    }

    @Override
    public List<ProductVO> productList(ProductParam productParam) {
        log.debug("商品列表业务:{}",productParam);
        List<ProductVO> list = productMapper.productList(productParam);
        return list;
    }

    @Override
    public List<ProductVO> productListByName(String name) {
        log.debug("通过名称查询商品列表业务:{}",name);
        List<ProductVO> list = productMapper.productListByName(name);
        return list;
    }

    @Override
    public ProductVO selectProductById(Long id) {
        log.debug("查询单个商品业务:{}",id);
        ProductVO productVO = productMapper.selectProductById(id);
        return productVO;
    }

    @Override
    public void deleteProductById(Long id) {
        log.debug("删除商品业务:{}",id);
        productMapper.deleteProductById(id);
    }

    @Override
    public void updateProduct(ProductParam productParam) {
        log.debug("修改商品业务:{}",productParam);
        productMapper.updateProduct(productParam);
    }


}
